package com.chucang.shucang.usr.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.chucang.shucang.common.base.page.PageData;
import com.chucang.shucang.common.base.utils.R;
import com.chucang.shucang.common.security.annotation.Inner;
import com.chucang.shucang.usr.entity.UserBillRecordEntity;
import com.chucang.shucang.usr.service.UserBillRecordService;
import com.chucang.shucang.usr.vo.BillPageResVO;
import com.chucang.shucang.usr.vo.query.BillQuery;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 用户账单
 *
 * @author flitsneak flitsneak@gmail.com
 * @since 1.0.0 2022-10-22
 */
@RestController
@RequestMapping("/userbillrecord")
@RequiredArgsConstructor
@Api(tags = "用户账单")
public class UserBillRecordController {

    private final UserBillRecordService userBillRecordService;

    /**
     * 账单完成
     *
     * @param billSn
     * @return
     */
    @Inner
    @GetMapping("/finishBill/{billSn}")
    public R<String> finishBill(@PathVariable String billSn) {
        LambdaUpdateWrapper<UserBillRecordEntity> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(UserBillRecordEntity::getBillSn, billSn)
                .set(UserBillRecordEntity::getStatus, 1);
        userBillRecordService.update(lambdaUpdateWrapper);
        return R.ok();
    }

    /**
     * 用户账单分页
     * @param billQuery
     * @return
     */
    @PostMapping("/billPage")
    public R<PageData<BillPageResVO>> billPage(@Valid @RequestBody BillQuery billQuery){
        PageData<BillPageResVO> pageData = userBillRecordService.billPage(billQuery);
        return R.ok(pageData);
    }
}